<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>个人资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">个人资料</div>
                <div class="layui-card-body" pad15>

                    <div id="base-info-edit-form" class="layui-form" lay-filter="base-info-edit-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="text" name="username" class="layui-input" disabled="">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="radio" name="gender" value="1" title="男">
                                <input type="radio" name="gender" value="0" title="女">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号码</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="text" name="mobile" lay-verify="required|phone" placeholder="请输入号码"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">真实姓名</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="text" name="realName" lay-verify="required" placeholder="请输入真实姓名"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="text" name="email" lay-verify="required|email" placeholder="请输入邮箱"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">角色</label>
                            <div class="layui-input-inline" style="width:300px;">
                                <input type="text" name="roleNames" class="layui-input" disabled="">
                            </div>
                        </div>
                        <!--<div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id"/>
                                <button class="layui-btn" lay-submit lay-filter="base-info-modify-submit">确认修改</button>
                            </div>
                        </div>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/layuiadmin/layui/layui.js}" charset="utf-8"></script>
<script>
;!function() {
    var form = layui.form,
    element = layui.element,
    $ = layui.jquery;
    var userInfo = layui.data('admin').userInfo;
    $.ajax({
        url: '/admin/user/base/info/modify/inquiry',
        type: 'post',
        contentType: "application/json",
        dataType: 'json',
        data: JSON.stringify({'id':userInfo.id}),
        success: function(data) {
            if (data.transactionStatus.success) {
                //var roleNames = new Array();
                //$.each(result.dataList,
                //function(i, item) {
                //roleNames.push(item.roleName);
                //});
                form.val("base-info-edit-form", {
                    "id": data.id,
                    "username": data.username,
                    "mobile": data.mobile,
                    "realName": data.realName,
                    "email": data.email,
                    "roleNames": data.roles
                });
                $("input[name=gender][value=0]").attr("checked", data.gender == 0 ? true: false);
                $("input[name=gender][value=1]").attr("checked", data.gender == 1 ? true: false);
                form.render();
            } else {
                layer.msg(data.transactionStatus.replyText);
            }
        }
    });
    form.on('submit(base-info-modify-submit)',
    function(data) {
        var field = data.field; //获取提交的字段
        //提交 Ajax 成功后，静态更新表格中的数据
        $.ajax({
            url: '/admin/user/base/info/modify',
            type: 'post',
            dataType: 'text',
            data: field,
            success: function(data) {
                if (data.transactionStatus.success) {
                    layer.msg("修改成功");
                } else {
                    layer.msg(data.transactionStatus.replyText);
                }
            }
        });
    });
}();

</script>
</body>
</html>